package com.example.administrator.u17.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.u17.R;
import com.example.administrator.u17.application.MyApplication;
import com.example.administrator.u17.modle.Paihang;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/11/14.
 */

public class YuePiaoBaseAdapter extends BaseAdapter {
    private Context context;
    private List<Paihang.Data.ReturnData.Comics> mData;
    private int type;
    private MyApplication myApplication;
    public YuePiaoBaseAdapter(Context context, List<Paihang.Data.ReturnData.Comics> mData, int type) {
        this.context = context;
        this.mData = mData;
        this.type = type;
        myApplication=new MyApplication();
    }

    @Override
    public int getCount() {
        return  mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = View.inflate(context, R.layout.item_yuepiao, null);
            vh = new ViewHolder(view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        Picasso.with(context).load(mData.get(i).cover).into(vh.iv1);
        if (i == 0) {
            vh.iv2.setImageResource(R.mipmap.icon_ranking_first);
            vh.iv2.setVisibility(View.VISIBLE);
        } else if (i == 1) {
            vh.iv2.setImageResource(R.mipmap.icon_ranking_second);
            vh.iv2.setVisibility(View.VISIBLE);
        } else if (i == 2) {
            vh.iv2.setImageResource(R.mipmap.icon_ranking_third);
            vh.iv2.setVisibility(View.VISIBLE);

        } else {
            vh.iv2.setVisibility(View.GONE);
        }
        vh.tv1.setText(mData.get(i).name);
        vh.tv3.setText(mData.get(i).description);
        StringBuilder sb = new StringBuilder();
        for (int j = 0; j < mData.get(i).tags.size(); j++) {
            sb.append(mData.get(i).tags.get(j) + " ");
        }
        vh.tv2.setText(sb.toString());
        if (type == 1) {
            vh.tv4.setText("月票值：" +mData.get(i).conTag);
        }
        if (type == 2) {
            vh.tv4.setText("点击值：" +mData.get(i).conTag );
            myApplication.clickPage=mData.get(i).conTag;
        }
        if (type == 3) {
            vh.tv4.setText("吐槽值：" +mData.get(i).conTag);
        }
        if (type == 4) {
            vh.tv4.setText("新作值：" + mData.get(i).conTag);
        }
        return view;
    }

    public static class ViewHolder {
        private ImageView iv1, iv2;
        private TextView tv1, tv2, tv3, tv4;

        public ViewHolder(View view) {
            iv1 = (ImageView) view.findViewById(R.id.iv_item_paihang_info);
            iv2 = (ImageView) view.findViewById(R.id.iv_item_paihang_top);
            tv1 = (TextView) view.findViewById(R.id.tv_intem_yuepiao_title);
            tv2 = (TextView) view.findViewById(R.id.tv_intem_yuepiao_type);
            tv3 = (TextView) view.findViewById(R.id.tv_intem_yuepiao_neirong);
            tv4 = (TextView) view.findViewById(R.id.tv_intem_yuepiao_count);
        }
    }

}
